package com.cntv.viewmodeldemo.databinding

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import com.cntv.viewmodeldemo.R
import com.cntv.viewmodeldemo.livedata.MyLiveDataViewModel


/**
 * Created By Mahongyin
 * Date    2020/9/17 16:48
 *
 */
class KotlinActivity: AppCompatActivity() {
    private lateinit var myViewModel: MyLiveDataViewModel
    private lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)
        myViewModel = ViewModelProvider(this,ViewModelProvider.NewInstanceFactory())[MyLiveDataViewModel::class.java]
//        myViewModel = ViewModelProvider(this,ViewModelProvider.NewInstanceFactory()).get(MyLiveDataViewModel::class.java)
        binding.data = myViewModel
        binding.lifecycleOwner = this
    }
}